package com.terrace.core.mybatis.entity;

import java.io.Serializable;
import java.util.List;

/**
 * 分页
 * 
 * @author jiangyg
 *
 * @param <E>
 */
public class Pagination<E> implements Serializable {

	private static final long serialVersionUID = -8069824170854132880L;

	/**
	 * 页码--从1开始
	 */
	private int page = 1;

	/**
	 * 页面大小--每页多少条
	 */
	private int rows = 10;

	/**
	 * 排序字段名
	 */
	private String sort;

	/**
	 * 排序
	 */
	private Order order;
	
	/**
	 * 共有多少条
	 */
	private int total;
	
	/**
	 * 起始行数
	 */
	private int startRow;

	/**
	 * 结束行数
	 */
	private int endRow;
	
	/**
	 * 分页信号
	 */
	private Signal signal = Signal.DEFAULT;

	/**
	 * 结果集
	 */
	private List<E> result;
	
	/**
	 * 是否分页--默认分页，不分页则不执行统计查询，查询条数则默认100000
	 */
	private boolean isPagination = true;

	public Pagination() {
		super();
	}

	public Pagination(boolean isPagination) {
		this.isPagination = isPagination;
		if (!isPagination) {
			this.rows = 100000;
		}
	}

	public Pagination(int rows, boolean isPagination) {
		this.rows = rows;
		this.isPagination = isPagination;
	}

	public Pagination(int page, int rows) {
		this.page = page;
		this.rows = rows;
	}

	public List<E> getResult() {
		return result;
	}

	public void setResult(List<E> result) {
		this.result = result;
	}

	public int getEndRow() {
		return this.page * getRows();
	}

	public void setEndRow(int endRow) {
		this.endRow = endRow;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return this.rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public int getStartRow() {
		return this.page > 0 ? (this.page - 1) * getRows() : 0;
	}

	public void setStartRow(int startRow) {
		this.startRow = startRow;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	public Signal getSignal() {
		return signal;
	}

	public void setSignal(Signal signal) {
		this.signal = signal;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public boolean isPagination() {
		return isPagination;
	}

	public void setPagination(boolean isPagination) {
		this.isPagination = isPagination;
		if (!isPagination) {
			this.rows = 100000;
		}
	}

	@Override
	public String toString() {
		return "Page{" + "page=" + page + ", rows=" + rows + ", startRow=" + startRow + ", endRow=" + endRow
				+ ", total=" + total + "}";
	}

}
